package com.sooncode.project.focusservice.service;

import com.sooncode.project.core.finder.Finder;
import com.sooncode.project.core.finder.OType;
import com.sooncode.project.core.finder.Page;
import com.sooncode.project.core.finder.Sort;
import com.sooncode.project.core.model.Entity;
import com.sooncode.project.focusservice.model.TestLevel;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TestLevelService {
    public boolean add(Map map){
        TestLevel testLevel=new TestLevel();
        testLevel.add(map);
        return true;
    }
    public boolean modify(String id,Map map){
        TestLevel testLevel=getById(id);
        testLevel.modify(map);
        return true;
    }
    public boolean delete(String id){
        TestLevel testLevel=getById(id);
        testLevel.delete();
        return true;
    }
    public boolean copy(int fromAge,int toAge){
        List<TestLevel> levelList=new Finder<>(TestLevel.class)
                .byField("age",fromAge+"")
                .list();
        for(TestLevel testLevel:levelList){
            testLevel.setId(new Entity().getId());
            testLevel.setAge(toAge+"");
            testLevel.add();
        }
        return true;
    }
    public Page<TestLevel> getPageList(int pageSize, int pageIndex, Map map) {
        Sort.ASC("age");
        Sort.ASC("age");
        return new Finder<>(TestLevel.class).byMap(map).page(pageSize, pageIndex, Sort.ASC("age").add("itemCode", Sort.Type.asc).Desc("minScore"));
    }
    public TestLevel getById(String id){
        return new Finder<>(TestLevel.class).byId(id);
    }

}
